<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-row :gutter="10" class="mb8">
        <el-col :span="4">
          <el-input
            v-model="queryParams.pdCode"
            placeholder="请输入物料编码"
            clearable
            @keyup.enter.native="handleQuery"
            style="width: 100%"
          />
        </el-col>
        <el-col :span="4">
          <el-input
            v-model="queryParams.pdName"
            placeholder="请输入物料名称"
            clearable
            @keyup.enter.native="handleQuery"
            style="width: 100%"
          />
        </el-col>
        <el-col :span="4">
          <el-select
            v-model="queryParams.pdGoodType"
            placeholder="请选择物料类型"
            clearable
            style="width: 100%"
          >
            <el-option
              v-for="dict in getGbsGoodType"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-col>
        <el-col :span="4">
          <el-select
            v-model="queryParams.pdGoodAttr"
            placeholder="请选择物料属性"
            clearable
            style="width: 100%"
          >
            <el-option
              v-for="dict in getGbsGoodAttr"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-col>
        <el-col :span="4">
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-col>
      </el-row>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['wm:info:product:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="productList">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="物料编码" width="150" align="center" prop="pdCode" />
      <el-table-column label="物料名称" align="center" prop="pdName" />
      <el-table-column label="规格型号" align="center" prop="pdSpecType" />
      <el-table-column label="有效期" align="center" prop="pdValidDate" />
      <el-table-column label="单位" align="center" prop="pdGuName" />
      <el-table-column label="BOM" align="center" prop="pdBomCode" />
      <el-table-column label="物料类型" align="center" prop="pdGoodType">
        <template slot-scope="scope">
          <dict-tag :options="getGbsGoodType" :value="scope.row.pdGoodType" />
        </template>
      </el-table-column>
      <el-table-column label="物料属性" align="center" prop="pdGoodAttr">
        <template slot-scope="scope">
          <dict-tag :options="getGbsGoodAttr" :value="scope.row.pdGoodAttr" />
        </template>
      </el-table-column>
      <el-table-column label="物料分类" align="center" prop="pdGcName" />
      <el-table-column label="当前库存" align="center" prop="storageNum" />
      <el-table-column label="库存上限" align="center" prop="pdMax" />
      <el-table-column label="库存下限" align="center" prop="pdMin" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listProduct } from "@/api/yyj/wm/info/goods";

export default {
  name: "Product",
  dicts: ['gbs_good_type', 'gbs_good_attr'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 物料库存表格数据
      productList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        pdCode: null,
        pdName: null,
        pdSpecType: null,
        pdUnitType: null,
        pdGoodType: null,
        pdGoodAttr: null,
        pdGoodClass: null,
        isMaterial: 1
      },
    };
  },
  computed: {
    getGbsGoodAttr() {
      return this.dict.type.gbs_good_attr
    },
    getGbsGoodType() {
      return this.dict.type.gbs_good_type
    },
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询物料库存列表 */
    getList() {
      this.loading = true;
      listProduct(this.queryParams).then(response => {
        this.productList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 查询参数重置
    resetQueryParams() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        pdCode: null,
        pdName: null,
        pdSpecType: null,
        pdUnitType: null,
        pdGoodType: null,
        pdGoodAttr: null,
        pdGoodClass: null,
        isMaterial: 1
      };
      this.resetForm("queryForm");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetQueryParams();
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('yyj/wm/info/product/export', {
        ...this.queryParams
      }, `product_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
